import { createReducer } from '@reduxjs/toolkit';
import { login, logout } from '../actions/authActions';

interface AuthState {
  isAuthenticated: boolean;
  user: {
    username: string;
    token: string;
  } | null;
}

const initialState: AuthState = {
  isAuthenticated: false,
  user: null
};

export const authReducer = createReducer(initialState, (builder) => {
  builder
    .addCase(login, (state, action) => {
      state.isAuthenticated = true;
      state.user = action.payload;
    })
    .addCase(logout, (state) => {
      state.isAuthenticated = false;
      state.user = null;
    });
}); 